ln -sf $< $@
libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $^ -lpthread
# libxenguest
ln -sf $< $@
libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_CFLAGS) -o $@ $(GUEST_PIC_OBJS) -lz -lxenctrl -lpthread
-include $(DEPS)
#include <inttypes.h>
#include "xc_private.h"
#include "xg_private.h"
-
#include <stdarg.h>
+#include <pthread.h>
static __thread xc_error last_error = { XC_ERROR_NONE, ""};
#if DEBUG
char *safe_strerror(int errcode)
{
static __thread char errbuf[32];
-#ifdef __GLIBC__
- /* Broken GNU definition of strerror_r may not use our supplied buffer. */
- return strerror_r(errcode, errbuf, sizeof(errbuf));
-#else
- /* Assume we have the POSIX definition of strerror_r. */
- strerror_r(errcode, errbuf, sizeof(errbuf));
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+ char *strerror_str;
+
+ /*
+ * Thread-unsafe strerror() is protected by a local mutex. We copy
+ * the string to a thread-private buffer before releasing the mutex.
+ */
+ pthread_mutex_lock(&mutex);
+ strerror_str = strerror(errcode);
+ strncpy(errbuf, strerror_str, sizeof(errbuf));
+ errbuf[sizeof(errbuf)-1] = '\0';
+ pthread_mutex_unlock(&mutex);
+
return errbuf;
-#endif
}
/*